package com.javabasic.algorithm.sword_of_offer;

import java.util.Stack;

/**
 * @Author xiongmin
 * @ClassName 用两个栈实现队列
 * @Description TODO
 * @Date 2019/9/7 23:03
 * @Version 1.0
 **/
public class 用两个栈实现队列 {
    Stack<Integer> stack1 = new Stack<Integer>();
    Stack<Integer> stack2 = new Stack<Integer>();

    public void push(int node) {
        stack1.add(stack1.size(),node);
    }

    public int pop() {
        return stack1.remove(stack1.size());


    }

    public void push1(int node) {
        while (stack1.isEmpty() == false) {
            stack2.push(stack1.pop());
        }
        stack1.push(node);
        while (stack2.isEmpty() == false) {
            stack1.push(stack2.pop());
        }
    }

    public int pop1() {
        return stack1.pop();
    }

    public void push2(int node) {
        stack1.push(node);
    }

    public int pop2() {
        if (stack2.empty()) {
            while (stack1.isEmpty() == false) {
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }
}
